<template>
	<view class="packA">
		<view>
			分包a <text @click="shop">购物</text>
		</view>
		<image :src="url" mode=""></image>
		<view class="header">
			<u-button @click="form">form表单</u-button>
			<u-button @click="form1">asa</u-button>
		</view>
		<view class="" v-for="item in index" :key="item">
			<view class="week_table">
				<u-icon name="arrow-left"></u-icon>
				<u-card  :title="title">
					<view slot="body">
						<u-table>
								<u-tr>
									<u-td>
										<view class="time">
											
										</view>
									</u-td>
									<u-th v-for="item in week" :key="item.name">
										<view>{{item.name}}</view>
										<!-- <view>{{item.day}}</view> -->
									</u-th>				
								</u-tr>
								<u-tr>
									<u-td>
										<view class="time">
											上午
										</view>
									</u-td>
									<u-td v-for="item in week" :key="item.name">
										<!-- <view>{{item.name}}</view> -->
										<view>{{item.day}}</view>
									</u-td>
								</u-tr>
								<u-tr>
									<u-td>
										<view class="time">
											下午
										</view>
									</u-td>
									<u-td v-for="item in week" :key="item.name">
										<!-- <view>{{item.name}}</view> -->
										<view>{{item.day}}</view>
									</u-td>
								</u-tr>
						</u-table>
					</view>
				</u-card>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		methods: {
			form () {
				uni.navigateTo({
					url:'/A/form/index'
				})
			},
			shop () {
				uni.navigateTo({
					url:'/A/shop/shop'
				})
			},
			form1 () {
				uni.navigateTo({
					url:'/A/index/consumptionRecord'
				})
			},
			maxDay (day) {
				let date = new Date()
				let year = date.getFullYear()
				let month = date.getMonth() + 1
				let date1 = new Date(year,month,0)
				if(day > date1.getDate()) {
					return day - date1.getDate()
				} else {
					return day
				}
				
			},
			maxMonth (month1,day) {
				let date = new Date()
				let year = date.getFullYear()
				let month = date.getMonth() + 1
				let date1 = new Date(year,month,0)
				if(day > date1.getDate()) {
					return month1 + 1
				} else {
					return month1
				}
			},
			arrMonth () {
				let date = new Date()
				let year = date.getFullYear()
				let month = date.getMonth() + 1
				let date1 = new Date(year,month,0)
				let arr = []
				console.log(date1)
				for(let i=0;i<date1.getDate();i++) {
					arr[i] = this.obj(i+1)
				}
				console.log(arr)
				
			},
			obj (day) {
				let date = new Date()
				let year = date.getFullYear()
				let month = date.getMonth() + 1
				return new Date(year,month,day)
			}
		},
		onLoad() {
			console.log(1)
		},
		onReachBottom () {
			console.log('触底')
			this.index = this.index + 1
		},
		onPullDownRefresh () {
			console.log('上拉')
			this.index = 2
		},
		data () {
			return {
				week: [{name:'星期日',day:''},{name:'星期一',day:''},{name:'星期二',day:''}
				,{name:'星期三',day:''},{name:'星期四',day:''}
				,{name:'星期五',day:''},{name:'星期六',day:''}],
				title: 'card',
				index:2,
				url: '/static/aa.jpg'
			}
		},
		created() {
			let date = new Date()
			let year = date.getFullYear() // 当年
			let month = date.getMonth() + 1 // 当月
			let day = date.getDate() // 当天几号
			let weekday = date.getDay()
			this.week.map((res,index)=>{
				let num = weekday - index
				res.day = num >= 0 ? month +'/'+ (day - num) :this.maxMonth(month,day + Math.abs(num)) +'/'+ (this.maxDay(day + Math.abs(num)))
			})
			console.log(this.week)
			this.arrMonth()
		}
	}
</script>

<style lang="scss">
	.packA {
		display: flex;
		flex-direction: column;
		border: 1px solid #007AFF;
		.header {
			background-color: red;
			height: 20rpx;
		}
		.week_table {
			margin-top: 100rpx;
			.time {
				min-height: 110rpx;display: flex;align-items: center;justify-content: center;
			}
			.u-table {
				border-radius: 10rpx;
			}
		}
	}
</style>
